*     *****************************************************************  * 
*     *****************************************************************  * 
*       File-Name:      partycodes.do                                    *  
*       Date:           4 June 2016                                      * 
*       Author:         Gschwend                                         * 
*       Purpose:      	get district-level winners of first round        *
*                       who advance to second for France (national)      *
* 	    Input Files:    PTY_FRA_NAT_01_11_2012_ResultsDistrictsPACA_IDF_Redux       *
*       Data Output:    partycodes.dta                                   *              
*     ****************************************************************   * 
*     ****************************************************************   * 



version 14.2
clear
capture log close
set more off


**********************************************
* Specify your own local path to the dropbox *
**********************************************


* Thomas G.'s local (office) path:
* local path /Users/gschwend/Dropbox/Andre/OUP multilevel electoral behavior book/chapter 6/replication/


* Thomas G.'s local (Air) path:
* local path /Users/thomasgschwend/Dropbox/Andre/OUP multilevel electoral behavior book/chapter 6/replication/
 
 



use "PTY_FRA_NAT_01_11_2012_ResultsDistrictsPACA_IDF_Redux.dta", clear


*construct district variable

tostring districtcode, gen(con_number)
gen con_name = trim(subinstr(departementname,"-"," ", .))
fre con_name

gen district = con_name + " " + con_number
sort district

replace candidate1party = trim(candidate1party)
replace candidate2party = trim(candidate2party)
replace candidate3party = trim(candidate3party)

* These are the parties that advanced to 2nd round
* Thus voting for those parties is NOT wasting the vote.

gen party1 = .
replace party1 = 1 if candidate1party == "SOC" 
replace party1 = 2 if candidate1party == "UMP" 
replace party1 = 3 if candidate1party == "FN" 
replace party1 = 6 if candidate1party == "EELV" 
replace party1 = 1 if candidate1party == "PRG" 
replace party1 = 9 if candidate1party == "NC" 
replace party1 = 4 if candidate1party == "FG" 

gen party2 = .
replace party2 = 1 if candidate2party == "SOC" 
replace party2 = 2 if candidate2party == "UMP" 
replace party2 = 3 if candidate2party == "FN" 
replace party2 = 6 if candidate2party == "EELV" 
replace party2 = 1 if candidate2party == "PRG" 
replace party2 = 9 if candidate2party == "NC" 
replace party2 = 4 if candidate2party == "FG" 

gen party3 = .
replace party3 = 3 if candidate3party == "FN" 


keep party1 party2 party3 district departementname departementcode
ren district district_name
sort district_name
compress
save partycodes, replace






